package hxg.com.algorithm;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @author HeXiangGuang
 * @create 2022-06-15 10:32
 */
public class Test {
    public static void main (String args[])throws IOException {
        long a[]=new long[1001];
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String s[]=bf.readLine().split(" ");
        int k=Integer.parseInt(s[0]);
        int n=Integer.parseInt(s[1]);
        int m=1;
        int sum=0;
        while(n>0){
            a[m++]=n%2;
            n=n/2;
        }
        m--;
        for(int i=1;i<=m;i++){
            sum+=a[i]*add(k,i-1);
            System.out.println(a[i]+" "+add(k,i-1)+" "+sum);
        }
        System.out.println(sum);
    }
    static int add(int k,int n){
        int sum=1;
        for(int i=1;i<=n;i++)
            sum*=k;
        return sum;
    }
}

